package com.example.ass7.dataloader;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;

import biuoop.KeyboardSensor;

import com.example.ass7.HighScoresTable;
import com.example.ass7.animation.AnimationRunner;
import com.example.ass7.animation.Menu;
import com.example.ass7.task.Task;

/**
 * @author Meirav Ben Izhak
 */
public class LevelSetReader {

    private String key;
    private String name;


    /**
     * @param reader reader
     * @param keyboardSensor keyboardSensor
     * @param highScoresTable highScoresTable
     * @param animationRunner animationRunner
     * @param menu menu
     * @throws IOException IOException
     */
    public void fromReader(Reader reader,
            KeyboardSensor keyboardSensor,
            HighScoresTable highScoresTable,
            AnimationRunner animationRunner,
            Menu<Task<Void>> menu) throws IOException {
        BufferedReader br = new BufferedReader(reader);
        boolean odd = Boolean.TRUE;
        while (br.ready()) {
            String line = br.readLine();
            if (line != null
                    && !line.isEmpty()) {

                line = line.trim();
                if (line.startsWith("#")) {
                    continue;
                }

                if (odd) {
                    String[] pair = line.split(":");
                    if (pair != null
                            && pair.length == 2) {
                        this.key = pair[0];
                        this.name = pair[1];

                    }

                }

                odd = !odd;
            }

        }
    }
}